package com.biz.primus.ms.coupon.trans;

import com.biz.primus.common.utils.CopyUtils;
import com.biz.primus.ms.coupon.dao.po.CouponType;
import com.biz.primus.ms.coupon.dao.ro.CouponTypeRo;
import java.util.function.Function;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 转换器 CouponType -> CouponTypeRo
 *
 * @author david-liu
 */
public class CouponType2CouponTypeRo implements Function<CouponType, CouponTypeRo> {
    @Override
    public CouponTypeRo apply(CouponType couponType) {
        CouponTypeRo couponTypeRo = new CouponTypeRo();
        CopyUtils.copyProperties(couponType, couponTypeRo);
        couponTypeRo.setBrands(CollectionUtils.isEmpty(couponType.getBrands()) ? "" : StringUtils.join(couponType.getBrands(), ","));
        couponTypeRo.setCategories(CollectionUtils.isEmpty(couponType.getCategories()) ? "" : StringUtils.join(couponType.getCategories(), ","));
        couponTypeRo.setIncludeProducts(CollectionUtils.isEmpty(couponType.getIncludeProducts()) ? "" : StringUtils.join(couponType.getIncludeProducts(), ","));
        couponTypeRo.setExcludeProducts(CollectionUtils.isEmpty(couponType.getExcludeProducts()) ? "" : StringUtils.join(couponType.getExcludeProducts(), ","));
        couponTypeRo.setVendors(CollectionUtils.isEmpty(couponType.getVendors()) ? "" : StringUtils.join(couponType.getVendors(), ","));
        return couponTypeRo;
    }
}
